package com.yami.shop.live.multishop.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.live.common.model.LiveProdLog;
import com.yami.shop.live.common.service.LiveProdLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author LGH
 * @date 2020-08-04 16:57:17
 */
@RestController
@RequestMapping("/live/liveProdLog")
@Tag(name = "商家端直播间商品日志接口")
public class LiveProdLogController {

    @Autowired
    private LiveProdLogService liveProdLogService;

    @GetMapping("/page")
    @Operation(summary =  "分页查找直播间商品列表日志信息")
    public ServerResponseEntity<IPage<LiveProdLog>> getLiveProdLogPage(PageParam<LiveProdLog> page,@ParameterObject LiveProdLog liveProdLog) {
        return ServerResponseEntity.success(liveProdLogService.page(page, new LambdaQueryWrapper<LiveProdLog>()));
    }

    @GetMapping("/info/{liveProdLogId}")
    @Operation(summary =  "通过id查询直播间商品日志")
    @Parameter(name = "liveProdLogId", description = "直播间商品记录id", required = true)
    public ServerResponseEntity<LiveProdLog> getById(@PathVariable("liveProdLogId") Long liveProdLogId) {
        return ServerResponseEntity.success(liveProdLogService.getById(liveProdLogId));
    }

    @PostMapping
    @Operation(summary =  "新增直播间商品日志")
    public ServerResponseEntity<Boolean> save(@RequestBody @Valid LiveProdLog liveProdLog) {
        return ServerResponseEntity.success(liveProdLogService.save(liveProdLog));
    }

    @PutMapping
    @Operation(summary =  "修改直播间商品日志")
    public ServerResponseEntity<Boolean> updateById(@RequestBody @Valid LiveProdLog liveProdLog) {
        return ServerResponseEntity.success(liveProdLogService.updateById(liveProdLog));
    }

    @DeleteMapping("/{liveProdLogId}")
    @Operation(summary =  "通过id删除直播间商品日志")
    @Parameter(name = "liveProdLogId", description = "直播间商品记录id", required = true)
    public ServerResponseEntity<Boolean> removeById(@PathVariable Long liveProdLogId) {
        return ServerResponseEntity.success(liveProdLogService.removeById(liveProdLogId));
    }
}
